package com.ruoyi.wechat.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.wechat.domain.Image;
import com.ruoyi.wechat.domain.CommunicationVo;
import com.ruoyi.wechat.mapper.ImageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wechat.mapper.CommunicationidMapper;
import com.ruoyi.wechat.domain.Communicationid;
import com.ruoyi.wechat.service.ICommunicationidService;

/**
 * 营地交流Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-12-31
 */
@Service
public class CommunicationidServiceImpl implements ICommunicationidService 
{
    @Autowired
    private CommunicationidMapper communicationidMapper;
    @Autowired
    private ImageMapper imageMapper;

    /**
     * 查询营地交流
     * 
     * @param communicationId 营地交流主键
     * @return 营地交流
     */
    @Override
    public Communicationid selectCommunicationidByCommunicationId(String communicationId)
    {
        return communicationidMapper.selectCommunicationidByCommunicationId(communicationId);
    }

    /**
     * 查询营地交流列表
     * 
     * @param communicationid 营地交流
     * @return 营地交流
     */
    @Override
    public List<Communicationid> selectCommunicationidList(Communicationid communicationid)
    {
        return communicationidMapper.selectCommunicationidList(communicationid);
    }

    /**
     * 新增营地交流
     * 
     * @param communicationid 营地交流
     * @return 结果
     */
    @Override
    public int insertCommunicationid(Communicationid communicationid)
    {
        return communicationidMapper.insertCommunicationid(communicationid);
    }

    /**
     * 修改营地交流
     * 
     * @param communicationid 营地交流
     * @return 结果
     */
    @Override
    public int updateCommunicationid(Communicationid communicationid)
    {
        return communicationidMapper.updateCommunicationid(communicationid);
    }

    /**
     * 批量删除营地交流
     * 
     * @param communicationIds 需要删除的营地交流主键
     * @return 结果
     */
    @Override
    public int deleteCommunicationidByCommunicationIds(String[] communicationIds)
    {
        return communicationidMapper.deleteCommunicationidByCommunicationIds(communicationIds);
    }

    /**
     * 删除营地交流信息
     * 
     * @param communicationId 营地交流主键
     * @return 结果
     */
    @Override
    public int deleteCommunicationidByCommunicationId(String communicationId)
    {
        return communicationidMapper.deleteCommunicationidByCommunicationId(communicationId);
    }

    /**
     * 查询所有评论信息
     * @return
     */
    @Override
    public List<CommunicationVo> select() {
        List<CommunicationVo> comm = communicationidMapper.select();
        for (int i = 0;i<comm.size();i++){
            String image = imageMapper.selectImageBycommunicationeId(comm.get(i).getCommunicationId());
            comm.get(i).setImage(image);
        }
        return comm;
    }

    /**
     * 保存评论信息
     * @param communicationVo
     * @return
     */
    @Override
    public int insertCommunicationVo(CommunicationVo communicationVo) {
        communicationVo.setCommunicationId(IdUtils.randomUUID());
        communicationVo.setTime(new Date());
        if (communicationVo.getImage() != null && communicationVo.getImage() != "") {
            Image image = new Image();
            image.setImageId(IdUtils.randomUUID());
            image.setCommunicationId(communicationVo.getCommunicationId());
            image.setUrl(communicationVo.getImage());
            imageMapper.insertImage(image);
        }
        Communicationid communicationid = new Communicationid();
        communicationid.setCommunicationId(communicationVo.getCommunicationId());
        communicationid.setContent(communicationVo.getContent());
        communicationid.setUserId(communicationVo.getUserId());
        communicationid.setTime(communicationVo.getTime());
        return communicationidMapper.insertCommunicationid(communicationid);
    }
}















